package com.toe.forum.webapi.controller;


import com.toe.common.restful.JsonResult;
import com.toe.forum.service.ForumRemarkService;
import com.toe.pojo.dto.forum.RemarkAddDTO;
import com.toe.pojo.dto.forum.RemarkSelectDTO;
import com.toe.pojo.vo.forum.RemarkDetailVO;
import com.toe.pojo.vo.forum.RemarkVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/forum-remark")
@Api(tags = "评论模块")
public class ForumRemarkController {

    @Autowired
    private ForumRemarkService forumRemarkService;

    @ApiOperation("添加评论")
    @PostMapping("/insert")
    public JsonResult<Void> insert(@RequestBody RemarkAddDTO remarkAddDTO){
        forumRemarkService.insert(remarkAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除评论")
    @PostMapping("/delete")
    public JsonResult<Void> delete(long id){
        forumRemarkService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询一篇文章全部评论")
    @PostMapping("/select/{articleId}")
    public JsonResult<List<RemarkVO>> selectLevelOneRemark(@PathVariable long articleId){
        List<RemarkVO> remarkDetailVOS = forumRemarkService.selectRemark(articleId);
        return JsonResult.ok(remarkDetailVOS);
    }

    @ApiOperation("查询一篇文章全部评论数量")
    @PostMapping("/select/count/{articleId}")
    public JsonResult<Integer> selectRemarkCount(@PathVariable long articleId){
        int count = forumRemarkService.selectRemarkCount(articleId);
        return JsonResult.ok(count);
    }

    @ApiOperation("分页查询一篇文章全部评论")
    @PostMapping("/select/page")
    public JsonResult<List<RemarkVO>> selectLevelOneRemarkPage(@RequestBody RemarkSelectDTO remarkSelectDTO){
        long articleId = remarkSelectDTO.getArticleId();
        Integer pageNum = remarkSelectDTO.getPageNum();
        Integer pageSize = remarkSelectDTO.getPageSize();
        List<RemarkVO> remarkDetailVOS = forumRemarkService.selectRemarkPage(articleId,pageNum,pageSize);
        return JsonResult.ok(remarkDetailVOS);
    }

    @ApiOperation("查询一篇文章全部评论包括回复")
    @PostMapping("/select/all/{articleId}")
    public JsonResult<List<RemarkDetailVO>> selectAllRemark(@PathVariable long articleId){
        List<RemarkDetailVO> remarkDetailVOS = forumRemarkService.selectAllRemark(articleId);
        return JsonResult.ok(remarkDetailVOS);
    }

    @ApiOperation("分页查询一篇文章全部评论包含回复")
    @PostMapping("/select/all/page")
    public JsonResult<List<RemarkDetailVO>> selectAllRemarkPage(@RequestBody RemarkSelectDTO remarkSelectDTO){
        long articleId = remarkSelectDTO.getArticleId();
        Integer pageNum = remarkSelectDTO.getPageNum();
        Integer pageSize = remarkSelectDTO.getPageSize();
        List<RemarkDetailVO> remarkDetailVOS = forumRemarkService.selectAllRemarkPage(articleId, pageNum, pageSize);
        return JsonResult.ok(remarkDetailVOS);
    }
}

